import 'package:flutter/material.dart';
import 'package:junyeyishu/utils/utils.dart';
import 'package:junyeyishu/widgets/QGWidget.dart';

class QGCircleCheckWidget extends StatefulWidget {
  bool select;
  double? size;
  String? image;
  EdgeInsets? padding;
  void Function(bool select)? onTap;

  QGCircleCheckWidget(
      {super.key,
      this.select = false,
      this.onTap,
      this.size,
      this.image,
      this.padding});

  @override
  State<StatefulWidget> createState() => QGCircleCheckWidgetState();
}

class QGCircleCheckWidgetState extends State<QGCircleCheckWidget> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        widget.select = !widget.select;
        setState(() {});
        if (widget.onTap != null) {
          widget.onTap!(widget.select);
        }
      },
      child: Row(
        children: [
          Container(
            color: Colors.transparent,
            padding: widget.padding ?? EdgeInsets.all(10.rpx),
            child: Container(
              width: widget.size ?? 12.rpx,
              height: widget.size ?? 12.rpx,
              decoration: widget.select
                  ? null
                  : BoxDecoration(
                      color: Colors.white,
                      borderRadius:
                          BorderRadius.circular((widget.size ?? 12.rpx) / 2),
                      border: Border.all(color: const Color(0xffA9A9A9))),
              child: widget.select
                  ? QGImage(
                      asset: widget.image ?? "pay_select",
                      width: widget.size ?? 12.rpx)
                  : null,
            ),
          ),
        ],
      ),
    );
  }
}
